]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
signalTracker: Use WeakMap in SignalManager to avoid leaking objects
authorSebastian Keller <skeller@gnome.org>
Sun, 28 Aug 2022 22:03:50 +0000 (00:03 +0200)
committerMarge Bot <marge-bot@gnome.org>
Mon, 29 Aug 2022 21:53:58 +0000 (21:53 +0000)
The object the SignalTracker belongs to is stored in a map managed by
the SignalManager which keeps a reference to that object. This map is
never destroyed nor is any entry ever removed. This leads to all objects
that ever had SignalTrackers used on them being kept alive even after
all references outside of the SignalTracker are long gone. This then
also extends to other objects which are leaked indirectly through
reference chains from these objects.

And if some of those objects are GObjects, this will prevent them from
being finalized, leaking further resources. A StWidget for example will
not release its shadow textures.

Fix this by using a WeakMap in SignalManager.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5807
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5796
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2450>

js/misc/signalTracker.js

index 1c3f4f9df4d17b53ceed4d7aa56886be0a0da7ca..8444564df4d1727de4fc17a571f2f41b85f3d22c 100644 (file)
@@ -42,7 +42,7 @@ class SignalManager {
     }
 
     constructor() {
-        this._signalTrackers = new Map();
+        this._signalTrackers = new WeakMap();
     }
 
     /**